<template>
    <div>
        <el-upload
            style="margin: 7px 5px 0px 0px"
            class="upload-demo"
            :action="uploadUrl"
            :before-upload="beforeAvatarUpload"
            :http-request="uploadBefore"
            :show-file-list="false"
            name="files"
            id="file"
        >
            <el-button size="small" type="primary" style="margin: 10px"
                >点击上传</el-button
            >
        </el-upload>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    props: [],
    data () {
        return {
            uploadUrl: 'http://192.168.100.100:1027/upload/files'
        }
    },
    mounted () {},
    methods: {
        //文件大小
        beforeAvatarUpload (file) {
            const isLt2M = file.size / 1024 / 1024 < 20
            if (!isLt2M) {
                this.clientPop('err', '上传文件大小不能超过 20MB！')
            }
            return isLt2M
        },
        uploadBefore (params) {
            const formData = new FormData()
            formData.append('files', params.file)
            formData.append('fileName', params.file.name)
            axios.post(`/node/upload/files?filename=${params.file.name}`,  formData ).then(val => {
                console.log(val)
            })
        },
    }
}
</script>

<style lang="less" scoped></style>
